<?php
namespace Isas\Controller;
use Think\Controller;
/**
 * 模块cms公共抽象支持类
 * @author wsf
 *
 */
abstract class AbstractIsasSupportController extends AbstractBaseController {
	
	protected static $progress = null;
	
	/**
	 * 获取所有代码
	 * @param object $model
	 */
	protected  function getAllCodes($model){
		return $model->field('code')
			->order('code asc')
			->group('code')			
			->select();
	}
	
	/**
	 * 根据代码获取所有bars
	 * @param object $model
	 * @param int $code
	 * @param string $idcField
	 */
	protected function getIdcCalcBars($model,$code,$idcField){
		return $model->field('id,close,bar_index,'.$idcField)
			->order('bar_index asc')
			->where('code = '.$code.' and '.$idcField.'=-1')
			->select();
	}
	
	public function getProgress(){
		if($this::$progress == null){
			$this::$progress = M('progress');
		}
		$data = $this::$progress->where('id=1')->select();
		echo $data[0]['total'].'|'.$data[0]['current'].'|'.$data[0]['msg'].'|'.$data[0]['status'];
	}
	
	protected function startProgress($total,$current,$msg){
		if($this::$progress == null){
			$this::$progress = M('progress');
		}
		$data['total'] = $total;
		$data['current'] = $current;
		//$data['percent']=round($total-$current);
		$data['msg'] = $msg;
		$data['status'] = 1;
		$this::$progress->where('id=1')->save($data);
	}
	
	protected function stopProgress(){
		if($this::$progress == null){
			$this::$progress = M('progress');
		}
		$data['status']=0;
		$this::$progress->where('id=1')->save($data);
	}
}